﻿using Microsoft.AspNetCore.SignalR.Client;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace IceDog.OTM.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            string host = "localhost:5000";
            string url = $"http://{host}/gameHub";
            HubConnection connection = new HubConnectionBuilder()
                .WithUrl(url)
                .Build();
            connection.Closed += async (error) =>
            {
                await Task.Delay(new Random().Next(1, 5) * 1000);
                await connection.StartAsync();
            };
            while (connection.State == HubConnectionState.Disconnected)
            {
                try
                {
                    connection.StartAsync().Wait();
                }
                catch {
                    //nothing
                }
                Task.Delay(2000).Wait();
            }
            int id = 0;
            while (true)
            {
                connection.SendAsync("AddScore", 1, 999).Wait();
                Thread.Sleep(5000);
            }
        }
    }
}
